<template>
  <el-cascader
    :value="value"
    :props="defaultProps"
    :options="options"
    separator="|"
    @change="handleChange"
  />
</template>

<script>
import { newArr } from '@/utils'
import { getDepartment } from '@/api/department'

export default {
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      defaultProps: {
        value: 'id',
        label: 'name',
        children: 'children'
      },
      // value: [],
      options: []
    }
  },
  created() {
    this.getDepartmentList()
  },
  methods: {
    handleChange(value) {
      console.log(value)
      const id = value[value.length - 1]
      console.log(id)
      this.$emit('input', id)
    },
    async getDepartmentList() {
      const res = await getDepartment()
      console.log(res)
      const options = newArr(res.data, 0)
      this.options = options
    }
  }
}
</script>

<style>

</style>
